#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL");

int cpu_value[2] = {13, 49};
void **cpu_p = NULL;

void test_per_cpu(void)
{
	int i = 0, cpu; 
	void *value;

	cpu_p = (void **)alloc_percpu(int *);
	if (!cpu_p) {
		printk(KERN_ERR "alloc failed \n");
		return;
	}

	for_each_possible_cpu(i) {
		*per_cpu_ptr(cpu_p, i) = cpu_value + i;
	}

	for (i = 0; i < 10; i++) {
        	schedule_timeout(HZ * 1000);
		cpu = get_cpu();
		value = per_cpu_ptr(cpu_p, cpu);
		put_cpu();
		printk(KERN_ERR "value:%d \n", *((int *)value));
	}
}

static __init int test_init(void)
{
	printk(KERN_ERR "test init \n");
	test_per_cpu();
	return 0;
}

static __exit void test_exit(void)
{
	printk(KERN_ERR "test exit \n");
}

module_init(test_init);
module_exit(test_exit);

